

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="zh-CN" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="zh-CN" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>robot.sdk.AliSpeech &mdash; wukong-robot 1.2.0 文档</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../_static/language_data.js"></script>
        <script type="text/javascript" src="../../../_static/translations.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="索引" href="../../../genindex.html" />
    <link rel="search" title="搜索" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html" class="icon icon-home"> wukong-robot
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">wukong-robot</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">模块代码</a> &raquo;</li>
        
      <li>robot.sdk.AliSpeech</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>robot.sdk.AliSpeech 源代码</h1><div class="highlight"><pre>
<span></span><span class="c1"># -*- coding: UTF-8 -*-</span>

<span class="kn">import</span> <span class="nn">http.client</span>
<span class="kn">import</span> <span class="nn">urllib.parse</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">from</span> <span class="nn">robot</span> <span class="k">import</span> <span class="n">utils</span>
<span class="kn">from</span> <span class="nn">robot</span> <span class="k">import</span> <span class="n">logging</span>

<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

<div class="viewcode-block" id="processGETRequest"><a class="viewcode-back" href="../../../robot.sdk.html#robot.sdk.AliSpeech.processGETRequest">[文档]</a><span class="k">def</span> <span class="nf">processGETRequest</span><span class="p">(</span><span class="n">appKey</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">voice</span><span class="p">,</span> <span class="n">text</span><span class="p">,</span> <span class="nb">format</span><span class="p">,</span> <span class="n">sampleRate</span><span class="p">)</span> <span class="p">:</span>
    <span class="n">host</span> <span class="o">=</span> <span class="s1">&#39;nls-gateway.cn-shanghai.aliyuncs.com&#39;</span>
    <span class="n">url</span> <span class="o">=</span> <span class="s1">&#39;https://&#39;</span> <span class="o">+</span> <span class="n">host</span> <span class="o">+</span> <span class="s1">&#39;/stream/v1/tts&#39;</span>
    <span class="c1"># 设置URL请求参数</span>
    <span class="n">url</span> <span class="o">=</span> <span class="n">url</span> <span class="o">+</span> <span class="s1">&#39;?appkey=&#39;</span> <span class="o">+</span> <span class="n">appKey</span>
    <span class="n">url</span> <span class="o">=</span> <span class="n">url</span> <span class="o">+</span> <span class="s1">&#39;&amp;token=&#39;</span> <span class="o">+</span> <span class="n">token</span>
    <span class="n">url</span> <span class="o">=</span> <span class="n">url</span> <span class="o">+</span> <span class="s1">&#39;&amp;text=&#39;</span> <span class="o">+</span> <span class="n">text</span>
    <span class="n">url</span> <span class="o">=</span> <span class="n">url</span> <span class="o">+</span> <span class="s1">&#39;&amp;format=&#39;</span> <span class="o">+</span> <span class="nb">format</span>
    <span class="n">url</span> <span class="o">=</span> <span class="n">url</span> <span class="o">+</span> <span class="s1">&#39;&amp;sample_rate=&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">sampleRate</span><span class="p">)</span>
    <span class="n">url</span> <span class="o">=</span> <span class="n">url</span> <span class="o">+</span> <span class="s1">&#39;&amp;voice=&#39;</span> <span class="o">+</span> <span class="n">voice</span>
    <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
    <span class="n">conn</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">HTTPSConnection</span><span class="p">(</span><span class="n">host</span><span class="p">)</span>
    <span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="s1">&#39;GET&#39;</span><span class="p">,</span> <span class="n">url</span><span class="o">=</span><span class="n">url</span><span class="p">)</span>
    <span class="c1"># 处理服务端返回的响应</span>
    <span class="n">response</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span>
    <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Response status and response reason:&#39;</span><span class="p">)</span>
    <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="p">,</span><span class="n">response</span><span class="o">.</span><span class="n">reason</span><span class="p">)</span>
    <span class="n">contentType</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="s1">&#39;Content-Type&#39;</span><span class="p">)</span>
    <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">contentType</span><span class="p">)</span>
    <span class="n">body</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
    <span class="k">if</span> <span class="s1">&#39;audio/mpeg&#39;</span> <span class="o">==</span> <span class="n">contentType</span> <span class="p">:</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;The GET request succeed!&#39;</span><span class="p">)</span>
        <span class="n">tmpfile</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">write_temp_file</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="s1">&#39;.mp3&#39;</span><span class="p">)</span>
        <span class="n">conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">tmpfile</span>
    <span class="k">else</span> <span class="p">:</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;The GET request failed: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">body</span><span class="p">))</span>
        <span class="n">conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="k">return</span> <span class="kc">None</span></div>

<div class="viewcode-block" id="processPOSTRequest"><a class="viewcode-back" href="../../../robot.sdk.html#robot.sdk.AliSpeech.processPOSTRequest">[文档]</a><span class="k">def</span> <span class="nf">processPOSTRequest</span><span class="p">(</span><span class="n">appKey</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">voice</span><span class="p">,</span> <span class="n">text</span><span class="p">,</span> <span class="nb">format</span><span class="p">,</span> <span class="n">sampleRate</span><span class="p">)</span> <span class="p">:</span>
    <span class="n">host</span> <span class="o">=</span> <span class="s1">&#39;nls-gateway.cn-shanghai.aliyuncs.com&#39;</span>
    <span class="n">url</span> <span class="o">=</span> <span class="s1">&#39;https://&#39;</span> <span class="o">+</span> <span class="n">host</span> <span class="o">+</span> <span class="s1">&#39;/stream/v1/tts&#39;</span>
    <span class="c1"># 设置HTTPS Headers</span>
    <span class="n">httpHeaders</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;Content-Type&#39;</span><span class="p">:</span> <span class="s1">&#39;application/json&#39;</span>
        <span class="p">}</span>
    <span class="c1"># 设置HTTPS Body</span>
    <span class="n">body</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;appkey&#39;</span><span class="p">:</span> <span class="n">appKey</span><span class="p">,</span> <span class="s1">&#39;token&#39;</span><span class="p">:</span> <span class="n">token</span><span class="p">,</span> <span class="s1">&#39;text&#39;</span><span class="p">:</span> <span class="n">text</span><span class="p">,</span> <span class="s1">&#39;format&#39;</span><span class="p">:</span> <span class="nb">format</span><span class="p">,</span> <span class="s1">&#39;sample_rate&#39;</span><span class="p">:</span> <span class="n">sampleRate</span><span class="p">,</span> <span class="s1">&#39;voice&#39;</span><span class="p">:</span> <span class="n">voice</span><span class="p">}</span>
    <span class="n">body</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">body</span><span class="p">)</span>
    <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;The POST request body content: &#39;</span> <span class="o">+</span> <span class="n">body</span><span class="p">)</span>
    <span class="c1"># Python 2.x 请使用httplib</span>
    <span class="c1"># conn = httplib.HTTPSConnection(host)</span>
    <span class="c1"># Python 3.x 请使用http.client</span>
    <span class="n">conn</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">HTTPSConnection</span><span class="p">(</span><span class="n">host</span><span class="p">)</span>
    <span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="s1">&#39;POST&#39;</span><span class="p">,</span> <span class="n">url</span><span class="o">=</span><span class="n">url</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">body</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">httpHeaders</span><span class="p">)</span>
    <span class="c1"># 处理服务端返回的响应</span>
    <span class="n">response</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span>
    <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Response status and response reason:&#39;</span><span class="p">)</span>
    <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="p">,</span><span class="n">response</span><span class="o">.</span><span class="n">reason</span><span class="p">)</span>
    <span class="n">contentType</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="s1">&#39;Content-Type&#39;</span><span class="p">)</span>
    <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">contentType</span><span class="p">)</span>
    <span class="n">body</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
    <span class="k">if</span> <span class="s1">&#39;audio/mpeg&#39;</span> <span class="o">==</span> <span class="n">contentType</span> <span class="p">:</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;The POST request succeed!&#39;</span><span class="p">)</span>
        <span class="n">tmpfile</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">write_temp_file</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="s1">&#39;.mp3&#39;</span><span class="p">)</span>
        <span class="n">conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">tmpfile</span>
    <span class="k">else</span> <span class="p">:</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s1">&#39;The POST request failed: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">body</span><span class="p">))</span>
        <span class="n">conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="k">return</span> <span class="kc">None</span></div>

<div class="viewcode-block" id="process"><a class="viewcode-back" href="../../../robot.sdk.html#robot.sdk.AliSpeech.process">[文档]</a><span class="k">def</span> <span class="nf">process</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">audioContent</span><span class="p">)</span> <span class="p">:</span>
    <span class="c1"># 读取音频文件</span>
    <span class="n">host</span> <span class="o">=</span> <span class="s1">&#39;nls-gateway.cn-shanghai.aliyuncs.com&#39;</span>
    <span class="c1"># 设置HTTP请求头部</span>
    <span class="n">httpHeaders</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;X-NLS-Token&#39;</span><span class="p">:</span> <span class="n">token</span><span class="p">,</span>
        <span class="s1">&#39;Content-type&#39;</span><span class="p">:</span> <span class="s1">&#39;application/octet-stream&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Content-Length&#39;</span><span class="p">:</span> <span class="nb">len</span><span class="p">(</span><span class="n">audioContent</span><span class="p">)</span>
        <span class="p">}</span>
    <span class="n">conn</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="n">host</span><span class="p">)</span>
    <span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="s1">&#39;POST&#39;</span><span class="p">,</span> <span class="n">url</span><span class="o">=</span><span class="n">request</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">audioContent</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">httpHeaders</span><span class="p">)</span>
    <span class="n">response</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span>
    <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Response status and response reason:&#39;</span><span class="p">)</span>
    <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="p">,</span><span class="n">response</span><span class="o">.</span><span class="n">reason</span><span class="p">)</span>
    <span class="n">body</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Recognize response is:&#39;</span><span class="p">)</span>
        <span class="n">body</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">body</span><span class="p">)</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">body</span><span class="p">)</span>
        <span class="n">status</span> <span class="o">=</span> <span class="n">body</span><span class="p">[</span><span class="s1">&#39;status&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">status</span> <span class="o">==</span> <span class="mi">20000000</span> <span class="p">:</span>
            <span class="n">result</span> <span class="o">=</span> <span class="n">body</span><span class="p">[</span><span class="s1">&#39;result&#39;</span><span class="p">]</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Recognize result: &#39;</span> <span class="o">+</span> <span class="n">result</span><span class="p">)</span>
            <span class="n">conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">result</span>
        <span class="k">else</span> <span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s1">&#39;Recognizer failed!&#39;</span><span class="p">)</span>
            <span class="n">conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="k">return</span> <span class="kc">None</span>
    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;The response is not json format string&#39;</span><span class="p">)</span>
        <span class="n">conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="k">return</span> <span class="kc">None</span></div>

<div class="viewcode-block" id="tts"><a class="viewcode-back" href="../../../robot.sdk.html#robot.sdk.AliSpeech.tts">[文档]</a><span class="k">def</span> <span class="nf">tts</span><span class="p">(</span><span class="n">appKey</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">voice</span><span class="p">,</span> <span class="n">text</span><span class="p">):</span>
    <span class="c1"># 采用RFC 3986规范进行urlencode编码</span>
    <span class="n">textUrlencode</span> <span class="o">=</span> <span class="n">text</span>
    <span class="n">textUrlencode</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">parse</span><span class="o">.</span><span class="n">quote_plus</span><span class="p">(</span><span class="n">textUrlencode</span><span class="p">)</span>
    <span class="n">textUrlencode</span> <span class="o">=</span> <span class="n">textUrlencode</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;+&quot;</span><span class="p">,</span> <span class="s2">&quot;%20&quot;</span><span class="p">)</span>
    <span class="n">textUrlencode</span> <span class="o">=</span> <span class="n">textUrlencode</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;*&quot;</span><span class="p">,</span> <span class="s2">&quot;%2A&quot;</span><span class="p">)</span>
    <span class="n">textUrlencode</span> <span class="o">=</span> <span class="n">textUrlencode</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%7E</span><span class="s2">&quot;</span><span class="p">,</span> <span class="s2">&quot;~&quot;</span><span class="p">)</span>
    <span class="nb">format</span> <span class="o">=</span> <span class="s1">&#39;mp3&#39;</span>
    <span class="n">sampleRate</span> <span class="o">=</span> <span class="mi">16000</span>
    <span class="k">return</span> <span class="n">processPOSTRequest</span><span class="p">(</span><span class="n">appKey</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">voice</span><span class="p">,</span> <span class="n">text</span><span class="p">,</span> <span class="nb">format</span><span class="p">,</span> <span class="n">sampleRate</span><span class="p">)</span></div>

<div class="viewcode-block" id="asr"><a class="viewcode-back" href="../../../robot.sdk.html#robot.sdk.AliSpeech.asr">[文档]</a><span class="k">def</span> <span class="nf">asr</span><span class="p">(</span><span class="n">appKey</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">wave_file</span><span class="p">):</span>
    <span class="c1"># 服务请求地址</span>
    <span class="n">url</span> <span class="o">=</span> <span class="s1">&#39;http://nls-gateway.cn-shanghai.aliyuncs.com/stream/v1/asr&#39;</span>
    <span class="n">pcm</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">get_pcm_from_wav</span><span class="p">(</span><span class="n">wave_file</span><span class="p">)</span>
    <span class="c1"># 音频文件</span>
    <span class="nb">format</span> <span class="o">=</span> <span class="s1">&#39;pcm&#39;</span>
    <span class="n">sampleRate</span> <span class="o">=</span> <span class="mi">16000</span>
    <span class="n">enablePunctuationPrediction</span>  <span class="o">=</span> <span class="kc">True</span>
    <span class="n">enableInverseTextNormalization</span> <span class="o">=</span> <span class="kc">True</span>
    <span class="n">enableVoiceDetection</span>  <span class="o">=</span> <span class="kc">False</span>
    <span class="c1"># 设置RESTful请求参数</span>
    <span class="n">request</span> <span class="o">=</span> <span class="n">url</span> <span class="o">+</span> <span class="s1">&#39;?appkey=&#39;</span> <span class="o">+</span> <span class="n">appKey</span>
    <span class="n">request</span> <span class="o">=</span> <span class="n">request</span> <span class="o">+</span> <span class="s1">&#39;&amp;format=&#39;</span> <span class="o">+</span> <span class="nb">format</span>
    <span class="n">request</span> <span class="o">=</span> <span class="n">request</span> <span class="o">+</span> <span class="s1">&#39;&amp;sample_rate=&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">sampleRate</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">enablePunctuationPrediction</span> <span class="p">:</span>
        <span class="n">request</span> <span class="o">=</span> <span class="n">request</span> <span class="o">+</span> <span class="s1">&#39;&amp;enable_punctuation_prediction=&#39;</span> <span class="o">+</span> <span class="s1">&#39;true&#39;</span>
    <span class="k">if</span> <span class="n">enableInverseTextNormalization</span> <span class="p">:</span>
        <span class="n">request</span> <span class="o">=</span> <span class="n">request</span> <span class="o">+</span> <span class="s1">&#39;&amp;enable_inverse_text_normalization=&#39;</span> <span class="o">+</span> <span class="s1">&#39;true&#39;</span>
    <span class="k">if</span> <span class="n">enableVoiceDetection</span> <span class="p">:</span>
        <span class="n">request</span> <span class="o">=</span> <span class="n">request</span> <span class="o">+</span> <span class="s1">&#39;&amp;enable_voice_detection=&#39;</span> <span class="o">+</span> <span class="s1">&#39;true&#39;</span>
    <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Request: &#39;</span> <span class="o">+</span> <span class="n">request</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">process</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">pcm</span><span class="p">)</span></div>
    
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, wzpan

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>